require.config({
    baseUrl: '/',
    paths: {
        'js': 'js',
        'eventBind': 'js/eventbind',
        'avalon': 'scripts/avalon/avalon.shim',
        'art-dialog': 'scripts/art-dialog/dist/dialog',
        'require-css': 'scripts/require-css/css',
        'jquery': 'scripts/jquery/dist/jquery',
        'animate.css': 'scripts/animate.css',
        'tagsinput': 'scripts/bootstrap-tagsinput/dist/bootstrap-tagsinput',
        'font-awesome': 'scripts/font-awesome/css/font-awesome',
        'bootstrap': 'scripts/bootstrap/dist/js/bootstrap',
        'stickUp': 'scripts/stickUp/stickUp',
        'summernote': 'scripts/summernote/dist/summernote',
        'bs3-typeahead': 'scripts/bootstrap3-typeahead/bootstrap3-typeahead',
        'typeahead': 'scripts/typeahead.js/dist/typeahead.jquery',
        'bloodhound': 'scripts/typeahead.js/dist/bloodhound'
    },
    shim: {
        'bootstrap': {
            deps: ['jquery']
        },
        'stickUp': {deps: ['jquery']},
        'summernote': {deps: ['jquery']},
        'js/function': ['jquery'],
        'js/preHandle': ['jquery'],
        'art-dialog': ['jquery'],
        'summernote/../../lang/summernote-zh-CN': ['summernote'],
        'tagsinput': ['jquery', 'bs3-typeahead']//
        //'tagsinput': ['jquery', 'bloodhound', 'typeahead']
    },
    map: {
        '*': {
            'css': 'require-css'
        }
    }
});
//require(['css!bootstrap/../../css/bootstrap.css','css!animate.css/animate.css','css!font-awesome','css!summernote/../summernote.css']);
require(['jquery', 'stickUp', 'art-dialog', 'bootstrap', 'summernote', 'summernote/../../lang/summernote-zh-CN', 'eventBind/index', 'eventBind/login&register', 'eventBind/widget', 'js/function', 'tagsinput'], function ($) {

    (function(){
        var $nav = [];//$('#navHeader');
        if($nav.length !== 0){
            $nav.css('width', $nav.width());
            $nav.stickUp();
        }
    })();

    var routerHandler = {};
    var router = {
        use: function(path, fn){
            routerHandler[path] = fn;
        }
    };
    $('a[href^=\\#\\!\\/]').each(function (i, n) {
        var $that = $(n);
        var $mainContainer = $('#mainContainer');
        //var path = $that.attr('href').slice(3);
        $that.on('click', function () {
            $mainContainer.html(' <div class="col-md-5 col-md-offset-3 center" style="padding: 30px;border-radius: 10px;margin-top: 15%;margin-bottom: 10%;"><i class="fa fa-spin fa-4x fa-spinner"></i></div>');
            $('.nav li.active').removeClass('active');
            $that.closest('li').addClass('active');
            var rout = $that.attr('href').split('#!')[1];
            if(rout in routerHandler){
                $.get(rout, function(data){
                    $mainContainer.html(data);
                    routerHandler[rout].call($that);
                }).error(function(xhr){
                   $('body').html(xhr.responseText);
                });
            }
        });
    });

    router.use('/admin/article/add', function(){
        require(['eventBind/edit']);
        var $note = $('#articleText');
        $note.summernote({
            height: 300,
            minHeight: 300,
            lang: 'zh-CN'
        });
    });

    (function(){
        if(location.href.indexOf('#!/') !== -1){
            var href = location.href.split('#!/')[1];
            $('a[href^=\\#\\!\\/]').filter('[href*=' + href + ']').trigger('click');
        }
    })();

    $('body').removeAttr('style');
});
